package cn.iocoder.yudao.module.bpm.message.kafka.custom.processInstance;


import cn.iocoder.yudao.module.bpm.message.consts.ProcessInstanceStreamKey;
import cn.iocoder.yudao.module.bpm.message.handle.ProcessInstanceMessageHandle;
import cn.iocoder.yudao.module.bpm.message.rocketmq.dto.RocketMqBpmProcessInstanceCancelledMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;

@Slf4j
@RequiredArgsConstructor
public class KafkaProcessInstanceCancelledCustom {


    private final ProcessInstanceMessageHandle processInstanceMessageHandle;

    @KafkaListener(
            topics = ProcessInstanceStreamKey.PROCESS_INSTANCE_CLEAN_MSG_STREAM,
            groupId = ProcessInstanceStreamKey.PROCESS_INSTANCE_CLEAN_MSG_GROUP +"_" + "${spring.application.name}"
    )
    public void onMessage(RocketMqBpmProcessInstanceCancelledMessage message) {
        try {
            log.info("消费消息：{}", message);
            processInstanceMessageHandle.onProcessInstanceCleanMsg(message.getBpmProcessMessage());
        } catch (Exception e) {
            log.error("MQ消费失败", e);
            throw new RuntimeException(e.getMessage());
        }
    }

}
